home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
turbovis
/
tvtoyc01.zip
/
HELPBASE.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1994-01-07
|
16KB
|
711 lines
/*------------------------------------------------------------*/
/* filename - HelpBase.cpp */
/* */
/* function(s) */
/* Member function(s) of following classes */
/* THelpTopic */
/* THelpIndex */
/* THelpFile */
/*------------------------------------------------------------*/
/*------------------------------------------------------------*/
/* */
/* Turbo Vision - Version 1.0 */
/* */
/* */
/* Copyright (c) 1991 by Borland International */
/* All Rights Reserved. */
/* */
/*------------------------------------------------------------*/
#define Uses_TStreamableClass
#define Uses_TPoint
#define Uses_TStreamable
#define Uses_ipstream
#define Uses_opstream
#define Uses_fpstream
#define Uses_TRect
#include <tv.h>
#if !defined( __HELP_H )
#include "HelpBase.h"
#endif // __HELP_H
#if !defined( __UTIL_H )
#include "Util.h"
#endif // __UTIL_H
#if !defined( __STRING_H )
#include <string.h>
#endif // __STRING_H
#if !defined( __LIMITS_H )
#include <limits.h>
#endif // __LIMITS_H
#if !defined( __STAT_H )
#include <sys\stat.h>
#endif // __STAT_H
#if !defined( __CTYPE_H )
#include <ctype.h>
#endif // __CTYPE_H
#if !defined( __IO_H )
#include <io.h>
#endif // __IO_H
#pragma warn -dsz
#ifdef HELPEXTENSIONS
int THelpFile::oldFront;
int THelpFile::oldCount;
ushort THelpFile::oldTopics[THelpFile::maxOldTopics];
#endif
TCrossRefHandler crossRefHandler = notAssigned;
// THelpTopic
const char * const near THelpTopic::name = "THelpTopic";
void THelpTopic::write( opstream& os )
{
writeParagraphs( os );
writeCrossRefs( os );
}
void *THelpTopic::read( ipstream& is )
{
readParagraphs( is );
readCrossRefs( is );
width = 0;
lastLine = INT_MAX;
return this;
}
TStreamable *THelpTopic::build()
{
return new THelpTopic( streamableInit );
}
TStreamableClass RHelpTopic( THelpTopic::name,
THelpTopic::build,
__DELTA(THelpTopic)
);
THelpTopic::THelpTopic() : TObject()
{
paragraphs = 0;
numRefs = 0;
crossRefs = 0;
width = 0;
lastOffset = 0;
lastLine = INT_MAX;
lastParagraph = 0;
};
void THelpTopic::readParagraphs( ipstream& s )
{
int i, size;
TParagraph **pp;
int temp;
s >> i;
pp = ¶graphs;
while ( i > 0)
{
s >> size;
*pp = new TParagraph;
(*pp)->text = new char[size];
(*pp)->size = (ushort) size;
s >> temp;
(*pp)->wrap = Boolean(temp);
s.readBytes((*pp)->text, (*pp)->size);
pp = &((*pp)->next);
--i;
}
*pp = 0;
}
void THelpTopic::readCrossRefs( ipstream& s )
{
int i;
TCrossRef *crossRefPtr;
s >> numRefs;
crossRefs = new TCrossRef[numRefs];
for (i = 0; i < numRefs; ++i)
{
crossRefPtr = (TCrossRef *)crossRefs + i;
s.readBytes(crossRefPtr, sizeof(TCrossRef));
}
}
void THelpTopic::disposeParagraphs()
{
TParagraph *p, *t;
p = paragraphs;
while (p != 0)
{
t = p;
p = p->next;
delete t->text;
delete t;
}
}
THelpTopic::~THelpTopic()
{
TCrossRef *crossRefPtr;
disposeParagraphs();
if (crossRefs != 0)
{
crossRefPtr = (TCrossRef *)crossRefs;
delete [numRefs] crossRefPtr;
}
}
void THelpTopic::addCrossRef( TCrossRef ref )
{
TCrossRef *p;
TCrossRef *crossRefPtr;
p = new TCrossRef[numRefs+1];
if (numRefs > 0)
{
crossRefPtr = crossRefs;
memmove(p, crossRefPtr, numRefs * sizeof(TCrossRef));
delete [numRefs] crossRefPtr;
}
crossRefs = p;
crossRefPtr = crossRefs + numRefs;
*crossRefPtr = ref;
++numRefs;
}
void THelpTopic::addParagraph( TParagraph *p )
{
TParagraph *pp, *back;
if (paragraphs == 0)
paragraphs = p;
else
{
pp = paragraphs;
back = pp;
while (pp != 0)
{
back = pp;
pp = pp->next;
}
back->next = p;
}
p->next = 0;
}
void THelpTopic::getCrossRef( int i, TPoint& loc, uchar& length,
int& ref )
{
int oldOffset, curOffset, offset, paraOffset;
TParagraph *p;
int line;
TCrossRef *crossRefPtr;
paraOffset = 0;
curOffset = 0;
oldOffset = 0;
line = 0;
crossRefPtr = crossRefs + i;
offset = crossRefPtr->offset;
p = paragraphs;
while (paraOffset + curOffset < offset)
{
oldOffset = paraOffset + curOffset;
wrapText(p->text, p->size, curOffset, p->wrap);
++line;
if (curOffset >= p->size)
{
paraOffset += p->size;
p = p->next;
curOffset = 0;
}
}
loc.x = offset - oldOffset - 1;
loc.y = line;
length = crossRefPtr->length;
ref = crossRefPtr->ref;
}
char *THelpTopic::getLine( int line )
{
int offset, i;
TParagraph *p;
char buffer[256];
if (lastLine < line)
{
i = line;
line -= lastLine;
lastLine = i;
offset = lastOffset;
p = lastParagraph;
}
else
{
p = paragraphs;
offset = 0;
lastLine = line;
}
buffer[0] = 0;
while (p != 0)
{
while (offset < p->size)
{
--line;
strcpy(buffer, wrapText(p->text, p->size, offset, p->wrap));
if (line == 0)
{
lastOffset = offset;
lastParagraph = p;
return buffer;
}
}
p = p->next;
offset = 0;
}
buffer[0] = 0;
return buffer;
}
int THelpTopic::getNumCrossRefs()
{
return numRefs;
}
int THelpTopic::numLines()
{
int offset, lines;
TParagraph *p;
offset = 0;
lines = 0;
p = paragraphs;
while (p != 0)
{
offset = 0;
while (offset < p->size)
{
++lines;
wrapText(p->text, p->size, offset, p->wrap);
}
p = p->next;
}
return lines;
}
void THelpTopic::setCrossRef( int i, TCrossRef& ref )
{
TCrossRef *crossRefPtr;
if (i < numRefs)
{
crossRefPtr = crossRefs + i;
*crossRefPtr = ref;
}
}
void THelpTopic::setNumCrossRefs( int i )
{
TCrossRef *p, *crossRefPtr;
if (numRefs == i)
return;
p = new TCrossRef[i];
if (numRefs > 0)
{
crossRefPtr = crossRefs;
if (i > numRefs)
memmove(p, crossRefPtr, numRefs * sizeof(TCrossRef));
else
memmove(p, crossRefPtr, i * sizeof(TCrossRef));
delete [numRefs] crossRefPtr;
}
crossRefs = p;
numRefs = i;
}
void THelpTopic::setWidth( int aWidth )
{
width = aWidth;
}
void THelpTopic::writeParagraphs( opstream& s )
{
int i;
TParagraph *p;
int temp;
p = paragraphs;
for (i = 0; p != 0; ++i)
p = p->next;
s << i;
for(p = paragraphs; p != 0; p = p->next)
{
s << p->size;
temp = int(p->wrap);
s << temp;
s.writeBytes(p->tex